import 'dart:collection';

import 'package:auto_route/auto_route.dart';
import 'package:dio/dio.dart';
import 'package:tender_flutter/constant/api_path.dart';
import 'package:tender_flutter/http/api_response.dart';
import 'package:tender_flutter/http/http_utils.dart';

class ApiPayOrder {
  /// 支付下单
  /// goodsId 商品id
  /// channelType   支付渠道
  static Future getPayOrder<T>(
      {@required int goodsId, @required int channelType}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["checkTime"] = goodsId;
      params["type"] = channelType;
      final response = await HttpUtils.post(ApiPath.payOrder, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 供需发布支付
  /// market 供需发布之后的id
  /// type 支付渠道 参见 AppConstant
  static Future<ApiResponse<void>> marketPublishPay(
      {@required String market, @required int type}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["market"] = market;
      params["type"] = type;
      final response =
          await HttpUtils.postForm(ApiPath.marketPulishPay, params: params);
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 供需置顶支付
  static Future marketPlaceTop<T>(
      {int type, int id, int pushTopId, int station}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["id"] = id;
      params["pushtop_id"] = pushTopId;
      params["station"] = station;
      final response = await HttpUtils.post(ApiPath.placeTop, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 供应商发布支付
  /// market 供应商发布之后的id
  /// type 支付渠道 参见 AppConstant
  static Future<ApiResponse<void>> supplierJoinPay(
      {@required String company, @required int type}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["company"] = company;
      params["type"] = type;
      final response =
          await HttpUtils.postForm(ApiPath.supplierJoinPay, params: params);
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 已下单但未支付的订单进行支付
  /// orderId 消费记录中的id
  /// type 支付渠道 参见 AppConstant
  static Future waitOrderPay<T>(
      {@required int orderId, @required int type}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["id"] = orderId;
      params["type"] = type;
      final response = await HttpUtils.get(ApiPath.noPayInfo, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }
}
